package com.company.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jrue
 * @version 1.0
 * @date 2020/1/28 14:39
 * https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/
 * 给定一个 N 叉树，返回其节点值的前序遍历。
 */
public class NAryTreePreorderTraversal {
    List<Integer> list = new ArrayList<>();
    public List<Integer> preorder(Node root) {
        if (root != null) {
            list.add(root.val);
            for (int i = 0; i < root.children.size(); i++) {
                preorder(root.children.get(i));
            }
        }
        return list;
    }
}
